import re
def donationToJson(dic):
    flag_jzdw = True
    flag_lx = True
    flag_rkwz = True
    flag_slz = True
    data = {
        'jjh':"武汉红十字基金会"
    }
    for (k,v) in dic.items():
        if (re.search("单位",k) !=None or re.search("人",k) !=None) and flag_jzdw:

            data['jzdw']=v
            flag_jzdw=False
        if re.search("时间",k)!=None:
            data['rq']=v
        if (re.search("金额",k)!=None or re.search("捐赠额",k)!=None) and flag_lx:
            data['lx']="捐款"
            data['je']=v
            if (re.search("万", k) != None):
                sz = float(data['je'])*10000
                data['je'] = str(sz)

        if (re.search("品名",k)!=None or re.search("物资",k)!=None) and flag_rkwz:
            data['lx']="捐物"
            data['rkwz']=v
            flag_rkwz = False
        if re.search("规格",k)!=None and v!="无" and data.get('rkwz') != None:
            data['rkwz']=data['rkwz']+" "+v
        if re.search("数量",k)!=None and flag_slz:
            data['slz']=v
            flag_slz=False
        if re.search("计量",k)!=None:
            data['jldw']=v
    return data


def grantToJson(dic):
    flag_ffdw = True
    flag_lx = True
    flag_ffwz = True
    flag_slz = True
    data = {
        'jjh': "武汉红十字基金会"
    }
    for (k,v) in dic.items():
        if re.search("单位",k) !=None  and flag_ffdw:
            data['ffdw']=v
            flag_ffdw=False
        if re.search("时间",k)!=None:
            data['rq']=v

        if re.search("捐赠额",k)!=None and flag_lx:
            data['lx']="发款"
            data['je']=v
            if (re.search("万", k) != None):
                sz = float(data['je'])*10000
                data['je'] = str(sz)
        if (re.search("品名",k)!=None or re.search("物资",k)!=None) and flag_ffwz:
            data['lx']="发物"
            data['ffwz']=v
            flag_ffwz = False
        if re.search("规格",k)!=None and v!="无" and data.get('rkwz') != None:
            data['ffwz']=data['ffwz']+" "+v
        if re.search("数量",k)!=None and flag_slz:
            data['slz']=v
            flag_slz=False
        if re.search("计量",k)!=None:
            data['jldw']=v
    return data
